#include "DataStruct.fxh"
#include "States.fxh"
float4x4 mWorld;                  // World matrix for object
float4x4 mWorldViewProjection;    // World * View * Projection matrix
float3 vLightPt;
float4 vDiffuseColor = float4(0.5f,0.5f,0.5f,0.5f); 

//--------------------------------------------------------------------------------------
// This shader computes standard transform and lighting
//--------------------------------------------------------------------------------------
VS_OUTPUT_POSNORM RenderSphereVS( VS_INPUT_VERTNORM inVert )
{
    VS_OUTPUT_POSNORM Output;
	     
    // Transform the position from object space to homogeneous projection space
	// Be careful!!! use float4 although the input is float3!!!
	float3 pos = inVert.Pos;
	//if(pos.z < 0)
		//pos.z = 0;
	Output.Position = mul(float4(pos,1.0), mWorldViewProjection);
	Output.PosWorld = mul(float4(pos,1.0), mWorld).xyz;
	Output.NormWorld = normalize(mul(inVert.Normal,(float3x3)mWorld));
    
    return Output;    
}


//--------------------------------------------------------------------------------------
// This shader outputs the pixel's color by modulating the texture's
// color with diffuse material color
//--------------------------------------------------------------------------------------
float4 RenderSpherePS( VS_OUTPUT_POSNORM In ) : SV_TARGET
{ 
	float3 vWNormal = normalize(In.NormWorld);
	float3 vWPos = In.PosWorld;

	float3 vLightVec = normalize(vLightPt - vWPos);
	float diffuse = dot(vLightVec, vWNormal);
	return diffuse*vDiffuseColor;
}

//--------------------------------------------------------------------------------------
// Renders scene 
//--------------------------------------------------------------------------------------
technique11 RenderSphereTech
{
    pass P0
    {        
		SetRasterizerState(RenderMesh_RS);  
        SetVertexShader(CompileShader(vs_5_0, RenderSphereVS()));
		SetGeometryShader( NULL );
        SetPixelShader(CompileShader(ps_5_0, RenderSpherePS())); 
    }
}

